package com.econ.springboot.tdengine.demo.mybatis.domain;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.sql.Timestamp;

public class TagData<T> {
    public TagData(Long ts, T val, Byte quality) {
        this.ts = ts;
        this.val = val;
        this.quality = quality;
    }

    public TagData(Long ts,  Byte quality,TagType type) {
        this.ts = ts;
        this.val = getMockData(type);
        this.quality = quality;
    }

    private Long ts;
    private T val;
    private Byte quality;
    private Long tagId;

    public TagData() {

    }

    public Long getTs() {
        return ts;
    }

    public void setTs(Long ts) {
        this.ts = ts;
    }

    public T getVal() {
        return val;
    }

    public void setVal(T val) {
        this.val = val;
    }

    public Byte getQuality() {
        return quality;
    }

    public void setQuality(Byte quality) {
        this.quality = quality;
    }

    public Long getTagId() {
        return tagId;
    }

    public void setTagId(Long tagId) {
        this.tagId = tagId;
    }


    public T getMockData(TagType type) {
        switch (type) {
            case FLOAT:
                return (T) (Float) RandomUtil.getRandom().nextFloat();
            case DOUBLE:
                return (T) (Double) RandomUtil.getRandom().nextDouble();
            case INT:
                return (T) (Integer) RandomUtil.getRandom().nextInt();
            case BOOL:
                return (T) (Boolean) RandomUtil.getRandom().nextBoolean();

        }

        return null;
    }

    @Override
    public String toString() {
        return "TagData{" +
                "ts=" + ts +
                ", tagid=" + tagId +
                ", value=" + val +
                ", quality=" + quality +
                '}';
    }
}
